#@layout()
<script>
    $("#fair-add").validate({
        rules:{
        	//均交由后台验证
        },
        messages:{
         	//均交由后台验证
        },
        onkeyup:false,
        focusCleanup:true,
        success:"valid",
        submitHandler:function(form){
        var config = {
        "url":"/admin/fair/doAdd",
        data:$("#fair-add").serialize(),
        "method":"POST"
        };
        var backendTool = new BackendTool(config);
        backendTool.ajaxRequest();
        }
    });
    
    
    $("#province").change(function(){
		var val = $("#province").val();
		$.ajax({
            type: "post",
            url:"/platform/fair/region",
            datatype: "json",
            data: {"id": val},
            success: function (data) {
                if (data.length > 0) {
                    $("#city").empty();
                    $("#city").append("<option value=''>请选择</option>")
                    for (var i = 0; i < data.length; i++) {
                        $("#city").append("<option value=" + data[i].REGION_ID + " class=''>" + data[i].REGION_NAME + "</option>")
                    }
                }
            }
        })
    });
    
    
    function initUploader(id,width,height){
    	var srcStr;
        var uploader = WebUploader.create({
            auto: true,
            duplicate:true,
            swf:  '#(contextPath)/assets/front/web/script/upload/Uploader.swf',
            server: '#(contextPath)/admin/upload',
            pick: {
                id:id
            },
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
            }
        });
        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var up=$(id+"_prew");
            // 创建缩略图
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                up.html('文件正在上传中，请稍候')
            }, width, height);
        });
        //文件上传成功处理
        uploader.on( 'uploadSuccess', function( file,resp ) {
        	var up=$(id+"_prew");
        	
        	if(id=="#fileClick"){
        		var s='<img src="'+resp._raw+'" style="border-radius:50%;" width="55px;">';
        	}else{
        		var s='<img src="'+resp._raw+'"  width="200px;">';
        	}
        	
        	up.html(s);
        	$(id+"_hidden").val(resp._raw);
        });
        //文件上传失败处理
        uploader.on( 'uploadError', function( file ) {
        	layer.alert(file.name+"上传失败！！")
        });
        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
        });
    }  
    
    
    $(document).ready(function(){
    	initUploader('#fileClick',"55","55");
    	initUploader('#personal_photo',"100","100");
    });
</script>
#define main()
     <form class="form form-horizontal" id="fair-add">
        #include("fair-form.html")
     </form>
#end